home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / util / xsize_1.0 / misc.c < prev    next >
C/C++ Source or Header  |  1990-03-03  |  2KB  |  107 lines

  1. /* Auto: make
  2. */
  3.  
  4. #define SCREENTOP\
  5.    (screen->TopEdge << ((screen->ViewPort.Modes & LACE)? 0: 1))
  6.  
  7. #define Line(pair, xl, yt, xr, yb) \
  8. { pair->xs = xl; pair->ys = yt; pair->xe = xr; pair->ye = yb; ++pair; }
  9.  
  10. #define HLine(pair, xl, xr, y) Line(pair, xl, y, xr, y)
  11. #define VLine(pair, yt, yb, x) Line(pair, x, yt, x, yb)
  12.  
  13. IMPORT struct IntuitionBase *IntuitionBase;
  14.  
  15. IMPORT struct RastPort rp;
  16.  
  17. WORD OF;
  18.  
  19. typedef struct {
  20.     WORD xs, ys;
  21.     WORD xe, ye;
  22. } Pair;
  23.  
  24. Pair OldFrame[8];
  25. Pair NewFrame[8];
  26.  
  27. struct Screen *WhichScreen()
  28. {
  29.     REGISTER struct Screen *screen;
  30.     Forbid();
  31.     screen = IntuitionBase->FirstScreen;
  32.     while (screen && IntuitionBase->MouseY < SCREENTOP) {
  33.         screen = screen->NextScreen;
  34.     }
  35.     if (screen == NULL) {     /* Shouldn't happen */
  36.         screen = IntuitionBase->ActiveScreen;
  37.     }
  38.     Permit();
  39.     return screen;
  40. }
  41.  
  42. struct Window *WhichWindow(screen)
  43. struct Screen *screen;
  44. {
  45.     struct Layer *layer;
  46.     layer = (struct Layer *)WhichLayer(&screen->LayerInfo,
  47.       (LONG)screen->MouseX, (LONG)screen->MouseY);
  48.     if (layer) {
  49.         return (struct Window *)layer->Window;
  50.     } else {
  51.         return NULL;
  52.     }
  53. }
  54.  
  55. STATIC VOID MultiDraw(rp, pairs)
  56. struct RastPort *rp;
  57. Pair *pairs;
  58. {
  59.     REGISTER LONG i = 8;
  60.     REGISTER Pair *coord = pairs;
  61.  
  62.     while (i--) {
  63.         Move(rp, (LONG)coord->xs, (LONG)coord->ys);
  64.         Draw(rp, (LONG)coord->xe, (LONG)coord->ye);
  65.         coord++;
  66.     }
  67. }
  68.  
  69. VOID BuildFrame(xl, yt, xr, yb)
  70. WORD xl, yt, xr, yb;
  71. {
  72.     REGISTER LONG tx  = (xr - xl) / 3;
  73.     REGISTER LONG ty  = (yb - yt) / 3;
  74.     REGISTER Pair *pair = &NewFrame[0];
  75.  
  76.     HLine(pair, xl, xr, yt);
  77.     HLine(pair, xl, xr, yt + ty);
  78.     HLine(pair, xl, xr, yb - ty);
  79.     HLine(pair, xl, xr, yb);
  80.     VLine(pair, yt, yb, xl);
  81.     VLine(pair, yt, yb, xl + tx);
  82.     VLine(pair, yt, yb, xr - tx);
  83.     VLine(pair, yt, yb, xr);
  84. }
  85.  
  86. VOID EraseFrame()
  87. {
  88.     if (OF) {
  89.         MultiDraw(&rp, &OldFrame[0]);
  90.         OF = 0;
  91.     }
  92. }
  93.  
  94. VOID DrawFrame()
  95. {
  96.     REGISTER LONG i;
  97.  
  98.     WaitTOF();
  99.     EraseFrame();
  100.     MultiDraw(&rp, &NewFrame[0]);
  101.     i = 8;
  102.     while (i--) {
  103.         OldFrame[i] = NewFrame[i];
  104.     }
  105.     OF = 1;
  106. }
  107.